package entities;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;

import custom_types.Afm;
import custom_types.Date;
import custom_types.EmailAddress;
import custom_types.Rating;

@Entity
public class Broker extends User {
	@Embedded
	private Afm afm = new Afm();
	@Embedded
	private Rating rating = new Rating();
	@OneToMany(mappedBy="broker", fetch=FetchType.LAZY) 
	private List<Advertisement> ads = new ArrayList<Advertisement>();
	
	//Constructor
	public Broker(){}

	public Broker(String username, String password,  EmailAddress email, String name, String surname, Date registrationDate, Afm afm) {
		super(username, password, email, name, surname, registrationDate);
		this.afm = afm;
		
		//this.ads = ads;
	}

	//Getters
	public int getAfm() { 
		return this.afm.getAfm(); 
	}
	
	//public List<Advertisement> getAdvertisements() { return ads; }
	
	public double getRating() { 
		return this.rating.getRating(); 
	}
	
	//Setters
	public void setAfm(int afm) { 
		this.afm.setAfm(afm);
	}
	
	public void addAdvertisement(Advertisement ad){
		if (ad != null)
			ads.add(ad);
	}
	
	public Advertisement getAdvertisement(int i){
		return ads.get(i);
	}
	
	public void removeAdvertisement(Advertisement ad){
		if (ad != null)
			ads.remove(ad);
	}
	
	public List<Advertisement> getAllAdvertisements(){
		return this.ads;
	}
	
	public void addRating(double rating){
		this.rating.addRating(rating);
	}
	
}
